package A002lock8;

import java.util.concurrent.TimeUnit;

// 两个静态同步方法，2部手机，请问先打印邮件还是短信？
// -----sendEmail
// -----sendSMS

class Phone06 {
    public static synchronized void sendEmail() throws Exception {
        TimeUnit.SECONDS.sleep(4);
        System.out.println("-----sendEmail");
    }

    public static synchronized void sendSMS() throws Exception {
        System.out.println("-----sendSMS");
    }
}


public class A002_线程八锁_6 {
    public static void main(String[] args) throws InterruptedException {

        Phone06 phone06_1 = new Phone06();
        Phone06 phone06_2 = new Phone06();

        new Thread(() -> {
            try {
                phone06_1.sendEmail();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }, "A").start();

        Thread.sleep(100);

        new Thread(() -> {
            try {
                phone06_2.sendSMS();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }, "B").start();
    }
}

